Data used from https://www1.nyc.gov/site/doh/covid/covid-19-data.page
from IPython.display import HTML
HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.input').hide();
} else {
$('div.input').show();
}
code_show = !code_show
}
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()"><input type="submit" value="Click here to toggle on/off the raw code."></form>''')
import pandas as pd
from matplotlib import pyplot as plt
import numpy as np
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
import folium
df = pd.read_csv("https://raw.githubusercontent.com/nychealth/coronavirus-data/master/tests-by-zcta.csv")
df = df.dropna()
pop = pd.read_csv("/Users/apapiu/Downloads/2010+Census+Population+By+Zipcode+(ZCTA) (1).csv")
pop = pop.rename(columns={"Zip Code ZCTA":"Zip Code", "2010 Census Population":"Population"})
df = df.rename(columns = {"MODZCTA":"Zip Code"})
df["Zip Code"] = df["Zip Code"].astype("int")
df = pd.merge(pop[["Zip Code", "Population"]], df, on = "Zip Code")
df["Perc"] = (df["Positive"]/df["Population"])*100
df["Zip Code"] = df["Zip Code"].astype("str")
m = folium.Map(location=[40.693943, -73.985880], default_zoom_start=11, tiles='cartodbpositron')
folium.Choropleth(
geo_data="https://raw.githubusercontent.com/gdobler/nycep/master/d3/data/nyc-zip-code.json", # I found this NYC zipcode boundaries by googling
data=df[["Zip Code", "Positive"]], # my dataset
columns=['Zip Code', 'Positive'], # zip code is here for matching the geojson zipcode, sales price is the column that changes the color of zipcode areas
key_on='feature.properties.ZIP', # this path contains zipcodes in str type, this zipcodes should match with our ZIP CODE column
fill_color='Purples',
bins=[0, 0.1, 100, 250, 500, 750, 1000, 1250, 1500, 1700],
fill_opacity=0.75,
line_opacity=0.3,
name= "Number of Confirmed Positive",
nan_fill_color='grey'
).add_to(m)
# folium.GeoJson(
# data = 'vic_for_crime_2018.geojson',
# style_function = style_function
# ).add_to(world_map)
m
m = folium.Map(location=[40.693943, -73.985880], default_zoom_start=12, tiles='cartodbpositron')
folium.Choropleth(
geo_data="https://raw.githubusercontent.com/gdobler/nycep/master/d3/data/nyc-zip-code.json", # I found this NYC zipcode boundaries by googling
data=df[["Zip Code", "Perc"]], # my dataset
columns=['Zip Code', 'Perc'], # zip code is here for matching the geojson zipcode, sales price is the column that changes the color of zipcode areas
key_on='feature.properties.ZIP', # this path contains zipcodes in str type, this zipcodes should match with our ZIP CODE column
fill_color='Purples',
bins=[0, 0.2, 0.5, 0.75, 1, 1.25, 1.5, 2.3],
fill_opacity=0.75, line_opacity=0.3, name = "Percentage Positive",
nan_fill_color='grey'
).add_to(m)
m
x